package com.hl.qzzpbackend.handler;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.hl.qzzpbackend.model.enums.CheckStatusEnum;
import com.hl.qzzpbackend.model.enums.IsDeleteEnum;
import com.hl.qzzpbackend.model.enums.JobStateEnum;
import com.hl.qzzpbackend.model.enums.StatusEnum;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;
import java.util.Date;

/**
 * MybatisPlus 字段自动填充
 *
 * @author helong
 */
@Slf4j
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "isDelete", Integer.class, IsDeleteEnum.NOT_DELETE.getValue());
        this.strictInsertFill(metaObject, "status", Integer.class, StatusEnum.DISABLE.getValue());
        this.strictInsertFill(metaObject, "jobState", Integer.class, JobStateEnum.NO_PUB.getValue());
        this.strictInsertFill(metaObject, "checkStatus", Integer.class, CheckStatusEnum.NOT_REVIEWED.getValue());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateTime", Date.class, new Date());
    }
}